﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading;

namespace ServerYuGi.Helper
{
    public class WaitForMeManager
    {
        ManualResetEvent ResetEvent = new ManualResetEvent(false);
        List<int> results = new List<int>();
        public bool isWait = false;
        public bool isCancel = false;
        public WaitForMeManager()
        {

        }
        public void F5()
        {
            isWait = false;
            isCancel = false;
            ResetEvent.Reset();
        }
        public void Waiting()
        {
            isWait = true;
            isCancel = false;
            ResetEvent.Reset();
            ResetEvent.WaitOne();
        }
        /// <summary>
        /// Resume Event
        /// </summary>
        /// <param name="iscancel">neu true thi la cancel excute, con false la excute</param>
        /// <param name="results">List ket qua</param>
        public void Wakeup(bool iscancel,List<int> results)
        {
            if(iscancel)            
                isCancel = true;          
            else 
                this.results = results;
            isWait = false;
            ResetEvent.Set();
        }
        public List<int> GetResult()
        {
            return results;
        }
    }
}
